<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link href="https://static.yimifudao.com/yimicdn/layui/css/layui.css" rel="stylesheet">
  <title>登录</title>
</head>
<style>
  .container {
    width: 300px;
    margin: 0 auto;
    padding-top: 260px;
  }
</style>

<body>
  <div class="container">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">用户名：</label>
        <div class="layui-input-block">
          <input type="text" name="username" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">密 &nbsp;&nbsp; 码：</label>
        <div class="layui-input-block">
          <input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
          <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
      </div>
    </form>
  </div>

  <script src="https://static.yimifudao.com/yimicdn/jquery/jquery-3.3.1.min.js"></script>
  <script src="https://static.yimifudao.com/yimicdn/layui/layui.js"></script>
  <script>
    layui.use(['form', 'layer'], function () {
      var layer = layui.layer;
      var form = layui.form;

      //监听提交
      form.on('submit(formDemo)', function (data) {
        var index = layer.load(0);
        $.ajax({
          type: 'POST',
          url: '/checklogin',
          data: data.field,
          success: function (res) {
            if (res.code === 2000) {
              location.href = 'http://email-yimifudao.com:3000/home.html'
            } else {
              layer.msg('登录失败')
            }
          },
          error: function (err) {
            layer.msg('登录失败')
          },
          complete: function () {
            layer.close(index);
          }
        })
        return false;
      });
    });

  </script>
</body>

</html>